$(function() {
	$("#tjfx").css("background-color", "#84bfa6");
	getProductName();
	getGoodsName();
	
	getSuperTime();
	$('#publish').on('click', function() {
		getProductAnalysisByTime();
	});

});
// 获取前一天的时间
function getSuperTime() {
	var d = new Date();
	var str;
	var day = d.getDate();
	if (parseInt(day) < 2) {
		str = d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + day;
	} else {
		str = d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + (day - 1);
	}
	$("#date1").val(str);
}

function getProductAnalysisByTime() {
	var starttime = $("input[name='starttime']").val();
	var shopcode = $("input[name='productName']").val();
	var goodscode = $("input[name='goodsName']").val();
	var totalcount = $("input[name='totalcount']").val();
	$.ajax({
		url : "goods/getInsert",
		type : "post",
		dataType : "json",
		data : {
			shopcode : shopcode,
			goodscode : goodscode,
			starttime : starttime,
			totalcount : totalcount
		},
		success : function(data) {
			alert(data[0]);
		},
		error : function() {
			$.fly.tip({
				text : '新增失败',
				type : 'error'
			});
		}
	});

}

function excelExport() {

	$("#form_demo").submit();
}

/**
 * 加载店铺名称纬度
 */
function getProductName() {
	$.ajax({
		url : "goods/getShopName",
		type : "post",
		dataType : "json",
		async : false,
		success : function(data) {
			var html = "[";
		
			if (data.length > 0) {
				for (var i = 0; i < data.length; i++) {
					html += "{mc:'" + data[i].name + "'," + "dm:'"
							+ data[i].namecode + "'},";
				}
				html = html.substring(0, html.length - 1);
				html = html + "]";
				html = eval("(" + html + ")");
				
				name = data[0].namecode;

				/*
				 * var p = $("#hidden").val(); var name = ""; if (p == "" || p ==
				 * null) { name = data[0].namecode;
				 * $("#productnameMR").val(name); } else { name = p; }
				 */
				/**
				 * 加载默认数据
				 */
				var $from = $("#form_demo").data("flyForm");// 表单对象
				$from.getControl("productName").combobox({
					data : html, 
					textField : 'mc', 
					valueField : 'dm', 
					initValue : name
				 
				});
				/* pageAllList1(1,10); */
			}
		},
		error : function() {
			$.fly.tip({
				text : '店铺名称加载失败',
				type : 'error'
			});
		}
	});
}

/**
 * 加载商品名称纬度
 */
function getGoodsName() {
	$.ajax({
		url : "goods/getGoodsName",
		type : "post",
		dataType : "json",
		async : false,
		success : function(data) {
			var html = "[";
			if (data.length > 0) {
				for (var i = 0; i < data.length; i++) {
					html += "{mc:'" + data[i].name + "'," + "dm:'"
							+ data[i].namecode + "'},";
				}
				html = html.substring(0, html.length - 1);
				html = html + "]";
				html = eval("(" + html + ")");
				
				name = data[0].namecode;

			/*	var p = $("#hidden1").val();
				var name = "";
				if (p == "" || p == null) {
					name = data[0].namecode;
					$("#goodsnameMR").val(name);
				} else {
					name = p;
				}*/

				/**
				 * 加载默认数据
				 */
				var $from = $("#form_demo").data("flyForm");// 表单对象
				$from.getControl("goodsName").combobox({
					data : html, 
					textField : 'mc',
					valueField : 'dm', 
					initValue : name
				 
				});
				/* pageAllList1(1,10); */
			}
		},
		error : function() {
			$.fly.tip({
				text : '商品名称加载失败',
				type : 'error'
			});
		}
	});
}
